#ifndef REMOTEEXECUTOR_H
#define REMOTEEXECUTOR_H

#include <QObject>
#include <QPoint>
#include <QSize>
#include <QString>
#include <QUdpSocket>
#include <QJsonObject>
#include <QJsonDocument>

// 前向声明
class VideoReceiver;

class RemoteExecutor : public QObject
{
    Q_OBJECT

public:
    explicit RemoteExecutor(QObject *parent = nullptr);
    ~RemoteExecutor();

    // 初始化和配置
    bool initialize();
    void setTargetScreenSize(const QSize& size);
    void setNetworkInterface(VideoReceiver* receiver);
    void setListenPort(quint16 port);

    // 控制开关
    void enable();
    void disable();
    bool isEnabled() const;

    // 指令执行
    void executeMouseEvent(const QJsonObject& eventData);
    void executeKeyEvent(const QJsonObject& eventData);

signals:
    void enabled();
    void disabled();
    void commandExecuted(const QString& commandInfo);
    void errorOccurred(const QString& error);
    void commandReceived(const QString& commandInfo);

private slots:
    void onReadyRead();
    void onSocketError(QAbstractSocket::SocketError error);

private:
    void setupCommandExecution();
    void convertCoordinates(QPoint& point);
    void processCommand(const QJsonObject& command);

private:
    // 网络通信
    QUdpSocket* udpSocket;
    quint16 listenPort;
    
    // 核心组件
    VideoReceiver* videoReceiver;
    
    // 屏幕配置
    QSize targetScreenSize;
    
    // 状态
    bool isEnabledFlag;
    
    // 坐标转换
    double scaleX;
    double scaleY;
    
    // 系统特定实现
    #ifdef LINUX_PLATFORM
    int uinputFd;  // uinput文件描述符
    #endif
};

#endif // REMOTEEXECUTOR_H
